package rd.hardcore.ui.controls 
{
	import caurina.transitions.Tweener;
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.events.MouseEvent;
	import rd.hardcore.events.EqDataEvent;
	import rd.hardcore.params.GlobalParams;
	import rd.hardcore.ui.speakers.Baffle;
	import rd.hardcore.ui.tools.AcceleratorCursor;
	
	/**
	 * ...
	 * @author PRASS
	 */
	public class Controls extends Sprite
	{
		/* EVT */
		static public const OPEN_CLOSE	: String = "open_close";
		
		/* VAR */
		public var msk				: Sprite;
		public var bg				: ControlsBackground_FC;
		
		private var isOpen			: Boolean;
		private var initY			: int;
		private var selectCursor	: AcceleratorCursor;
		private var baffleL			: Baffle;
		private var baffleR			: Baffle;
		private var container		: Sprite;
		
		/* Controls */
		public function Controls() 
		{
			bg = new ControlsBackground_FC();
			addChildAt(bg, 0);
			
			container = new Sprite();
			addChild(container);
						
			msk = new Sprite();
			addChild(msk);
			
			msk.graphics.beginFill(0xFFF000, .5);
			msk.graphics.drawRect(0, 0, bg.width, bg.height);
			msk.graphics.endFill();
			
			mask = msk;
			initY = -msk.height - 1;
			
			bg.y = container.y = initY;
			
			selectCursor = new AcceleratorCursor();
			container.addChild(selectCursor);
			selectCursor.x = width - (selectCursor.width>>1) >> 1;
			selectCursor.y = 55;
			
			baffleL = new Baffle();
			container.addChild(baffleL);
			baffleL.x = 55;
			baffleL.y = 55;
			
			baffleR = new Baffle();
			container.addChild(baffleR);
			baffleR.x = 550 - 55;
			baffleR.y = 55;
			
			y = 340;
			x = (GlobalParams.WIDTH - width ) >> 1;
		}
		
		
		public function handleOpenClose( evt : Event ) : void
		{
			isOpen = !isOpen
			
			Tweener.removeTweens(container);
			Tweener.removeTweens(bg);
			
			if (isOpen)
			{
				Tweener.addTween(container, { y:0, time:.6} );
				Tweener.addTween(bg, 		{ y:0, time:.6} );
				
				addEventListener(MouseEvent.MOUSE_WHEEL, selectCursor.handleWheel);
				
			} else {

				Tweener.addTween(container, { y:initY, time:.4, transition:"easeInQuad" } );
				Tweener.addTween(bg, 		{ y:initY, time:.4, transition:"easeInQuad" } );
				
				removeEventListener(MouseEvent.MOUSE_WHEEL, selectCursor.handleWheel);
			}
		}
		
		public function updateSpeakers(e:EqDataEvent):void
		{
			if (isOpen) {
				baffleL.pumpItUp(e.level);
				baffleR.pumpItUp(e.level);
			}
		}
		
		
	}

}